package snooker.scoreboard.button;

import android.content.res.Resources;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.ImageView;

public abstract class AbstractControlButton extends AbstractThreeStateImage implements OnTouchListener, OnClickListener {
	
	protected AbstractControlButton(ImageView v, Resources r, int resource1, int resource2, int resource3) {
		super(v, r, resource1, resource2, resource3);
		setOnTouchListener(this);
		setOnClickListener(this);
	}
	
	public boolean onTouch(View v, MotionEvent event) {
		if (!isEnabled())
			return true;
		int action = event.getAction();
		switch (action) {
		case MotionEvent.ACTION_DOWN:
			setState2();
			actionDown();
			break;
		case MotionEvent.ACTION_UP:
			setState1();
			actionUp();
			break;
		}
		return true;
	}
	
	public void onClick(View v) {
		actionUp();
	}

	protected void actionDown() {
		
	}
	
	protected void actionUp() {
		
	}
}
